<?php
my_component_load('testing' , false);
my_component_load('paging' , false);
my_component_load('penilaian');
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$penilaian_id= isset( $_GET['penilaian_id'] ) ? $_GET['penilaian_id']:  0;
$karyawan_id = isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0;
$evaluasi_id = isset( $_GET['evaluasi_id'] ) ? $_GET['evaluasi_id']:  0;
//$nik_start = isset( $_GET['nik_start'] ) ? sprintf('%07d',(int) $_GET['nik_start']) :  '0000001';
//$nik_end = isset( $_GET['nik_end'] ) ? sprintf('%07d',(int) $_GET['nik_end']) :  '9999999' ;
	
$modulname = "Personalia _BN_ Pembinaan _BN_ Hasil Kerja";
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){ 
	case "upload_skor_page":
		upload_kenaikan_pa_csv($penilaian_id);
		generate_my_web('Updated',"","plain.php");
		exit;
	break;
	case "list_evaluasi":
		$total_nilai=$count_nilai=0;
			
		foreach($_POST['fskor'] as $key=>$val){
				
				my_query("DELETE FROM penilaian_karyawan_evaluasi WHERE karyawan_id ={$_GET['karyawan_id']} AND  evaluasi_id ={$key} ");
				$query = "INSERT penilaian_karyawan_evaluasi SET nilai = '{$val}'  
				,karyawan_id ={$_GET['karyawan_id']} ,
				evaluasi_id ={$key}  
				";  
			 my_query($query);
			$total_nilai+=$val;
			$count_nilai++;
			
			update_evaluasi($penilaian_id,$karyawan_id,$total_nilai,$count_nilai);
		}
		my_direct($_SERVER['HTTP_REFERER']);
		break;
	}

else: 	
	if($task == "list_karyawan"){
		$pagename = $modulname." _BN_ Karyawan ";
		load_facebox_script();
		$content = list_karyawan($penilaian_id); 
	}elseif($task == "upload_skor_page"){
		$content =  upload_form_page(); 
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == "upload_skor"){
		$title = "Upload final skor penilaian seluruh karyawan";
		facebox_page('index.php?com='.$_GET['com'].'&task=upload_skor_page&penilaian_id='.$penilaian_id , $title , 120	); 
	}elseif($task == "list_evaluasi"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Karyawan _BN_ Evaluasi ";
		$content = list_evaluasi($penilaian_id, $karyawan_id);
	}elseif($task == "plaincetak"){
		@ob_end_clean(); 
		echo'<pre>';
		echo print_plain($penilaian_id);
		exit;
	}elseif($task == "excel"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=penilaian".rand().".xls");
		echo excel_report($penilaian_id);
		exit;		
	}else{
		$pagename = $modulname;
		load_facebox_script();
		$content = list_penilaian();		
	}
endif;  
generate_my_web($content, $pagename  );
?>